from odoo import fields, models, api, _


class OrderMeterial(models.Model):
    _name = 'order.meterial'
    _description = '物料汇总'
    _inherit = ['mail.thread', 'mail.activity.mixin']

    name = fields.Char('名称', default=lambda s: _('New'), index=True, tracking=True, readonly=True)
    sale_ids = fields.One2many('sale.order', 'meterial_id', string='销售订单')
    line_ids = fields.One2many('order.meterial.line', 'meterial_id', string='物料明细')

    @api.model
    def create(self, values):
        if values.get('name', _('New')) == _('New'):
            values['name'] = self.env['ir.sequence'].next_by_code('order.meterial') or _('New')
        return super(OrderMeterial, self).create(values)



